package wai.school.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import wai.school.R;

/**
 * Created by Administrator on 2017/4/25.
 */

public class MainActivity1 extends AppCompatActivity{
    private Button[] mTabs;
    private int mIndex;//frgment和底部选项卡的索引
    private int mCurrentIndex;//当前选中frgment和底部选项卡的索引
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        initView();
    }

    private void initView() {
        mTabs=new Button[3];
        mTabs[0]= (Button) findViewById(R.id.btn_shouye);
        mTabs[1]=(Button) findViewById(R.id.btn_jiaoyi);
        mTabs[2]=(Button) findViewById(R.id.btn_wode);
        mTabs[0].setSelected(true);
    }
    public void onTabClicked(View v){
        switch (v.getId()){
            case R.id.btn_shouye:
                mIndex=0;
                break;
            case R.id.btn_jiaoyi:
                mIndex=1;
                break;
            case R.id.btn_wode:
                mIndex=2;
                break;
        }
        if(mCurrentIndex!=mIndex){
            mTabs[mIndex].setSelected(true);
            mTabs[mCurrentIndex].setSelected(false);
            mCurrentIndex=mIndex;
        }

    }
}
